package com.ruoyi.money.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.money.domain.SysUserTransaction;
import com.ruoyi.money.service.ISysUserTransactionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 收支明细Controller
 * 
 * @author ruoyi
 * @date 2025-08-18
 */
@RestController
@RequestMapping("/money/transaction")
public class SysUserTransactionController extends BaseController
{
    @Autowired
    private ISysUserTransactionService sysUserTransactionService;

    /**
     * 查询收支明细列表
     */
    @PreAuthorize("@ss.hasPermi('money:transaction:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysUserTransaction sysUserTransaction)
    {
        startPage();
        List<SysUserTransaction> list = sysUserTransactionService.selectSysUserTransactionList(sysUserTransaction);
        return getDataTable(list);
    }

    /**
     * 导出收支明细列表
     */
    @PreAuthorize("@ss.hasPermi('money:transaction:export')")
    @Log(title = "收支明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUserTransaction sysUserTransaction)
    {
        List<SysUserTransaction> list = sysUserTransactionService.selectSysUserTransactionList(sysUserTransaction);
        ExcelUtil<SysUserTransaction> util = new ExcelUtil<SysUserTransaction>(SysUserTransaction.class);
        util.exportExcel(response, list, "收支明细数据");
    }

    /**
     * 获取收支明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('money:transaction:query')")
    @GetMapping(value = "/{transactionId}")
    public AjaxResult getInfo(@PathVariable("transactionId") Long transactionId)
    {
        return success(sysUserTransactionService.selectSysUserTransactionByTransactionId(transactionId));
    }

    /**
     * 新增收支明细
     */
    @PreAuthorize("@ss.hasPermi('money:transaction:add')")
    @Log(title = "收支明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUserTransaction sysUserTransaction)
    {
        return toAjax(sysUserTransactionService.insertSysUserTransaction(sysUserTransaction));
    }

    /**
     * 修改收支明细
     */
    @PreAuthorize("@ss.hasPermi('money:transaction:edit')")
    @Log(title = "收支明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUserTransaction sysUserTransaction)
    {
        return toAjax(sysUserTransactionService.updateSysUserTransaction(sysUserTransaction));
    }

    /**
     * 删除收支明细
     */
    @PreAuthorize("@ss.hasPermi('money:transaction:remove')")
    @Log(title = "收支明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{transactionIds}")
    public AjaxResult remove(@PathVariable Long[] transactionIds)
    {
        return toAjax(sysUserTransactionService.deleteSysUserTransactionByTransactionIds(transactionIds));
    }
}
